package com.mask.mk.controller;


import com.mask.mk.service.AddressinfoService;
import com.mask.mk.util.JsonResult;
import com.mask.mk.vo.address.UpdateAddressRequest;
import com.mask.mk.vo.cart.AddCartRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 地址信息表 前端控制器
 * </p>
 *
 * @author joey
 * @since 2023-04-25
 */
@Api(tags = "地址管理")
@RestController
@RequestMapping("/addressinfo")
public class AddressinfoController {

    @Autowired
    private AddressinfoService addressinfoService;

    @ApiOperation(value = "添加地址")
    @PostMapping("/addAddress")
    public JsonResult addAddress(@RequestBody UpdateAddressRequest addressRequest){
        System.out.println(addressRequest);
        return addressinfoService.addUpdateAddressById(addressRequest);
    }

    @ApiOperation(value = "修改地址")
    @PostMapping("/updateAddress")
    public JsonResult updateAddress(@RequestBody UpdateAddressRequest addressRequest){
        System.out.println(addressRequest);
        return addressinfoService.addUpdateAddressById(addressRequest);
    }

    @ApiOperation(value = "删除地址")
    @PostMapping("/delAddress")
    public JsonResult delAddress(@RequestBody UpdateAddressRequest addressRequest){
        System.out.println(addressRequest);
        return addressinfoService.delAddress(addressRequest);
    }

    @ApiOperation(value = "获取地址列表") //userid
    @PostMapping("/getAddressList")
    public JsonResult getAddressList(@RequestBody UpdateAddressRequest addressRequest){
        System.out.println(addressRequest);
        return addressinfoService.queryAddressList(addressRequest);
    }

    @ApiOperation(value = "获取默认地址") // userId status 1
    @PostMapping("/getDefaultAddressList")
    public JsonResult getDefaultAddressList(@RequestBody UpdateAddressRequest addressRequest){
        System.out.println(addressRequest);
        return addressinfoService.queryOneDefault(addressRequest);
    }

}

